home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / src / loaders / Leander / leanderhd.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-03  |  4.7 KB  |  350 lines

  1. ; *** Leander Hard Disk Loader V1.3
  2. ; *** Written by Jean-François Fabre 1997-1998
  3.  
  4.     include    "jst.i"
  5.  
  6.     HD_PARAMS    "",0,0
  7.  
  8. HDLOAD = 1
  9.  
  10. TEST_FILE:MACRO
  11.     lea    disk\1file(pc),A0
  12.     move.l    A0,D0
  13.     JSRABS    TestFile
  14.     tst.l    D0
  15.     bne    FileErr
  16.     ENDM
  17.  
  18. loader:
  19.     RELOC_MOVEL    D0,trainer
  20.     RELOC_MOVEL    D4,buttonwait
  21.  
  22.     Mac_printf    "Leander HD Loader V1.3a"
  23.     Mac_printf    "Coded by Jean-François Fabre © 1997-1998"
  24.  
  25.     move.l    trainer(pc),D0
  26.     beq    trskip$
  27.  
  28.     NEWLINE
  29.     Mac_printf    "Trainer mode activated"
  30. trskip$
  31.     TEST_FILE    1
  32.     TEST_FILE    2
  33.     TEST_FILE    3
  34.  
  35.     bsr    ReadScores
  36.     tst.l    D0
  37.     beq    sk$
  38.  
  39.     Mac_printf    "** Could not read score file"
  40. sk$
  41.     move.l    #1000,D0
  42.     JSRABS    LoadSmallFiles
  43.  
  44.     ; *** try to find external memory (fails for 32bit memory)
  45.  
  46.     move.l    #$80000,D0
  47.     JSRABS    AllocExtMem
  48.     RELOC_MOVEL    D0,ExtBase
  49.     bne    suite$            ; OK
  50.  
  51.     ; *** 512K extension (may fail)
  52.  
  53. ;    RELOC_MOVEL    #$80000,ExtBase
  54. ;    RELOC_MOVEL    #$F,ExtFlag
  55. ;    bra    suite$
  56.  
  57.     ; *** only the 512K chipmem used
  58. noext$
  59.     RELOC_CLRL    ExtSize
  60.     RELOC_CLRL    ExtFlag
  61.     RELOC_CLRL    ExtBase
  62.  
  63. suite$
  64.  
  65.     moveq.l    #0,D0
  66.     move.l    #-1,D1
  67.     JSRABS    Degrade
  68.  
  69.     GO_SUPERVISOR
  70.     SAVE_OSDATA    $80000
  71.  
  72. LeanderBoot:
  73.     move.l    ExtBase(pc),D0
  74.     MOVE.L    ExtSize(pc),D1
  75.     MOVE.l    ExtFlag(pc),D2
  76.  
  77. ;;    MOVEA.L    #$00080000,A7
  78.     MOVEA.L    #$00DFF000,A6
  79.     JSRGEN    FreezeAll
  80.     MOVE.L    D0,$4.W        ; extension base pointer
  81.     MOVE.L    D1,$8.W        ; memory extension size
  82.  
  83.     ; *** Clear a zone from $400 to $70000
  84.  
  85.     MOVEA.L    #$00000400,A0
  86.     MOVE.L    #$0001BF00,D0
  87. clear$:
  88.     MOVE.L    #0,(A0)+
  89.     SUBQ.L    #1,D0
  90.     BNE    clear$
  91.  
  92.     lea    boot(pc),A0
  93.     lea    $400.W,A1
  94.     move.l    #endboot-boot-1,D0
  95.     lsr.l    #2,D0
  96.  
  97. copy$
  98.     move.l    (A0)+,(A1)+
  99.     dbf    D0,copy$
  100.  
  101.     PATCHUSRJMP    $66E.W,DiskRoutine
  102.     PATCHUSRJMP    $500.W,PatchLoader1
  103.     JSRGEN    FlushCachesHard
  104.  
  105.     JMP    $400.W
  106.  
  107. DiskRoutine:
  108.     cmp.b    #5,D1
  109.     beq    DR_DirRead
  110.     cmp.b    #0,D1
  111.     beq    DR_FileRead
  112.  
  113.     cmp.b    #1,D1
  114.     beq    DR_FileWrite
  115.  
  116.     moveq.l    #0,D0
  117.     JSRGEN    WaitMouse
  118.     bra    DR_End
  119.  
  120.     ; *** load the file
  121.  
  122. DR_FileRead:
  123.     moveq.l    #0,D0
  124.     moveq.l    #-1,D1
  125.     
  126.     JSRGEN    ReadFile
  127.     tst.l    D0
  128.     bmi    DR_End    ; not found : return -1 in D0
  129.  
  130.     bsr    WaitOnLevel
  131.  
  132.     move.l    D0,D1
  133.     moveq.l    #0,D0
  134.     bra    DR_End
  135.  
  136. ; *** read directory
  137.  
  138. DR_DirRead:
  139.     moveq.l    #0,D1
  140.     moveq.l    #0,D0    
  141.  
  142. DR_End:
  143.     MOVEM.L    (A7)+,D2-D7/A0-A6
  144.     RTS
  145.  
  146. ; *** other commands, still not supported
  147.  
  148. DR_Other:
  149.     cmp.w    #1,D1
  150.     beq    DR_FileWrite
  151.  
  152.     JSRGEN    WaitMouse
  153.     JSRGEN    InGameExit
  154.     bra    DR_Other
  155.  
  156. ; *** write file (only score)
  157. ; D0 holds the length to write but we ignore it
  158. ; because we write only the scores
  159.  
  160. DR_FileWrite:
  161.     ; *** if something else than the scorefile is written, ignore it
  162.  
  163.     move.l    A0,D1
  164.     GETUSRADDR    scorename
  165.     JSRGEN    StrcmpAsm
  166.     tst.l    D0
  167.     bne    notscore$
  168.  
  169.     ; *** copy the scores in fast memory
  170.  
  171.     lea    scorebuffer(pc),A2
  172.     move.w    #$C7,D1
  173. scopy$
  174.     move.b    (A1)+,(A2)+
  175.     dbf    D1,scopy$
  176.  
  177.     ; *** set the exit routine; so the scores will
  178.     ; *** be saved on exit
  179.  
  180.     lea    WSOnExit(pc),A0
  181.     JSRGEN    SetExitRoutine
  182.  
  183.     moveq.l    #0,D0
  184.     move.l    #$C8,D1
  185.     bra    DR_End
  186.  
  187. notscore$
  188.     JSRGEN    WaitMouse
  189.     moveq.l    #-1,D0
  190.     moveq.l    #0,D1
  191.     bra    DR_End
  192.  
  193.  
  194. WaitOnLevel
  195.     move.l    buttonwait(pc),D2
  196.     beq    sk$
  197.  
  198.     cmp.b    #'L',(A0)
  199.     bne    sk$
  200.     cmp.b    #'E',1(A0)
  201.     bne    sk$
  202.     cmp.b    #'V',2(A0)
  203.     bne    sk$
  204.  
  205. wb$
  206.     btst    #6,$bfe001
  207.     beq    sk$
  208.     btst    #7,$bfe001
  209.     bne    wb$
  210. sk$
  211.     rts
  212.  
  213.  
  214.  
  215. ReadScores:
  216.     lea    scorename(pc),A0
  217.     lea    scorebuffer(pc),A1
  218.     move.l    #$C8,D1
  219.     moveq.l    #0,D0
  220.     JSRGEN    ReadUserFileHD
  221.     rts
  222.  
  223. WSOnExit:
  224.     bsr    WriteScores
  225.     tst.l    D0
  226.     beq    wok$
  227.     Mac_printf    "** Could not save scores"
  228.     Mac_printf    "   Hit Return to exit"
  229.     JSRABS    WaitReturn
  230. wok$
  231.     rts
  232.  
  233. WriteScores:
  234.     lea    scorename(pc),A0
  235.     lea    scorebuffer(pc),A1
  236.     move.l    #$C8,D1
  237.     moveq.l    #0,D0
  238.     JSRGEN    WriteUserFileHD
  239.     rts
  240.  
  241.  
  242. FileErr:
  243.     Mac_printf    "** Please install the game properly"
  244.     JMPABS    CloseAll
  245.  
  246.  
  247. _UserPatchRoutines:
  248.  
  249. PatchLoader1:
  250.     bsr    LocalPatchExcept
  251.  
  252.     move.l    A0,-(sp)
  253.  
  254.     ; *** patch the disk routine
  255.  
  256.     PATCHUSRJMP    $5CC0.W,DiskRoutine    
  257.  
  258.     ; *** set up the new patch
  259.     ; *** at 2 locations
  260.  
  261.     PATCHUSRJMP    $5C1E.W,PatchLoader2
  262.     PATCHUSRJMP    $5BE8.W,PatchLoader2
  263.  
  264.     ; *** remove another disk routine
  265.  
  266.     move.l    #$60000204,$7778.W
  267.  
  268.     move.l    (sp)+,A0
  269.     jmp    $5AA0.W
  270.  
  271. PatchLoader2:
  272.     STORE_REGS
  273.     bsr    LocalPatchExcept
  274.  
  275.     ; *** remove another disk routine
  276.  
  277.     move.l    #$60000216,$7121A
  278.  
  279.     ; *** patch the disk routine
  280.  
  281.     PATCHUSRJMP    $704EC,DiskRoutine    
  282.  
  283.     ; *** install the quit key
  284.  
  285.     PATCHUSRJSR    $7FEA0,kbint
  286.  
  287.     ; *** remove life-decrease in case of trainer mode
  288.  
  289.     RELOC_TSTL    trainer
  290.     beq    trskip$
  291.  
  292.     move.l    #$4E714E71,D0
  293.     lea    $6BE58,A0
  294.     move.l    D0,(A0)+
  295.     move.l    D0,(A0)+
  296. trskip$
  297.  
  298.     RESTORE_REGS
  299.     jmp    $609F8
  300.  
  301. kbint:
  302.     move.b    #0,$C00(A0)
  303.     cmp.b    #$5F,D0
  304.     bne    noquit$
  305.     JSRGEN    InGameExit
  306. noquit$
  307.     rts
  308.  
  309.  
  310. LocalPatchExcept:
  311.     move.l    $8.W,-(sp)    ; used by the game to store data
  312.     JSRGEN    PatchExceptions
  313.     move.l    (sp)+,$8.W
  314.     rts
  315.  
  316.  
  317.  
  318. ExtBase:
  319.     dc.l    0
  320. ExtSize:
  321.     dc.l    0
  322. ExtFlag:
  323.     dc.l    0
  324. buttonwait:
  325.     dc.l    0
  326. trainer:
  327.     dc.l    0
  328.  
  329. scorebuffer:
  330.     blk.b    $C8,0
  331.     cnop    0,4
  332.  
  333. boot:
  334.     incbin    "chip.bin"
  335. endboot:
  336.     cnop    0,4
  337.  
  338. scorename:
  339.     dc.b    "SCORES",0
  340.  
  341.  
  342. disk1file:
  343.     dc.b    "PSYLOGO",0
  344.  
  345. disk2file:
  346.     dc.b    "WORLD1",0
  347.  
  348. disk3file:
  349.     dc.b    "QUEST3",0
  350.